package com.wanqing.controller.user;

import com.wanqing.assistant.UserAssistant;
import com.wanqing.assistant.pojo.UserChat;
import com.wanqing.context.BaseContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/user/assistant")
@Tag(name = "C端-智能客服相关接口")
@Slf4j
public class UserAssistantController {
    @Autowired
    private UserAssistant userAssistant;

    @PostMapping(value = "/chat",produces = "text/stream;charset=utf-8")
    @Operation(summary = "对话")
    public Flux<String> chat(@RequestBody UserChat userChat) {
        //查看当前线程
        log.info("当前线程:{}", Thread.currentThread());
        userChat.setUserId(BaseContext.getCurrentId());
        Flux<String> chat = userAssistant.chat(userChat, userChat.getContent(),userChat.getUserId());
        return chat;
    }

}
